package com.caishi.lkx.exam.api;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.caishi.lkx.course.mapper.VideoChapterMapper;
import com.caishi.lkx.course.mapper.VideoInfoMapper;
import com.caishi.lkx.course.model.VideoChapterModel;
import com.caishi.lkx.course.model.VideoInfoModel;
import com.caishi.lkx.exam.mapper.MaterialInfoMapper;
import com.caishi.lkx.user.model.MaterialInfoModel;
import com.zzw.common.annotation.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/free-resource")
public class FreeApi {
    private final MaterialInfoMapper materialInfoMapper;
    private final VideoChapterMapper videoChapterMapper;
    private final VideoInfoMapper videoInfoMapper;

    public FreeApi(VideoChapterMapper videoChapterMapper, MaterialInfoMapper materialInfoMapper, VideoInfoMapper videoInfoMapper) {
        this.videoChapterMapper = videoChapterMapper;
        this.materialInfoMapper = materialInfoMapper;

        this.videoInfoMapper = videoInfoMapper;
    }

    @ApiResult
    @GetMapping
    public Object free(@RequestParam(required = false) Long categoryId,@RequestParam String type) {
        // 分类获取
        if(type.equals("video")){
                // kc_video_chapter
            Page<VideoChapterModel> page = new Page<>(1, 5);
            List<VideoChapterModel> videoChapterModels = videoChapterMapper.selectFree(page);
            // 再获取阿里云视频id

            QueryWrapper<VideoInfoModel> queryWrapper = new QueryWrapper<>();


                    List<String> videoIds = new ArrayList<>();
            videoChapterModels.forEach(videoChapterModel -> {
//                List<String> videoIds = videoChapterModel.getVideoIds();
                // 获取阿里云视频id

            });
            queryWrapper.in("id", videoIds);
//            videoInfoMapper.selectList()
            return videoChapterModels;
        }else if(type.equals("material")){
            // sys_material_info
            QueryWrapper<MaterialInfoModel> queryWrapper = new QueryWrapper<>();
            queryWrapper.isNotNull("download_time");
            Page<MaterialInfoModel> page = new Page<>(1, 5);
            Page<MaterialInfoModel> materialInfoModelPage = materialInfoMapper.selectPage(page, queryWrapper);
            return materialInfoModelPage.getRecords();
        }
        return false;
    }
}
